package CompletableFuture.常用方法;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @program: algorithm
 * @description: thenApply、handle
 * @author: 陈恩涛
 * @create: 2022-08-09 23:12
 **/
public class CfApiDemo5 {
    public static void main(String[] args){


        final CompletableFuture<Integer> cf1 = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 10;
        });

        final CompletableFuture<Integer> cf2 = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 20;
        });

        System.out.println(cf1.thenCombine(cf2, Integer::sum).join());
    }
}
